package com.xgs.web.controller.system;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xgs.common.annotation.Log;
import com.xgs.common.core.controller.BaseController;
import com.xgs.common.core.domain.AjaxResult;
import com.xgs.common.core.domain.entity.SysUser;
import com.xgs.common.core.page.TableDataInfo;
import com.xgs.common.enums.BusinessType;
import com.xgs.common.utils.poi.ExcelUtil;
import com.xgs.system.domain.Lane;
import com.xgs.system.service.LaneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * @author JerryLu
 * @date 2024/10/23 11:05
 * @description 收费站信息数据Controller
 */
@RestController
@RequestMapping("/system/lane")
public class LaneController extends BaseController {
    @Autowired
    private LaneService laneService;

    /**
     * 查询收费站信息数据列表
     */
//    @PreAuthorize("@ss.hasPermi('system:lane:list')")
    @GetMapping("/list")
    public TableDataInfo list(Lane lane) {
        startPage();
        if (!SysUser.isAdmin(getUserId())) {
            lane.setOrgId(getDeptId());
        }
        List<Lane> list = laneService.queryList(lane);
        return getDataTable(list);
    }

    /**
     * 导出收费站信息数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:lane:export')")
    @Log(title = "收费站信息数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Lane lane) {
        List<Lane> list = laneService.queryList(lane);
        ExcelUtil<Lane> util = new ExcelUtil<Lane>(Lane.class);
        util.exportExcel(response, list, "收费站信息数据数据");
    }

    /**
     * 获取收费站信息数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:lane:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(laneService.getById(id));
    }

    /**
     * 新增收费站信息数据
     */
    @PreAuthorize("@ss.hasPermi('system:lane:add')")
    @Log(title = "收费站信息数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Lane lane) {
        return toAjax(laneService.save(lane));
    }

    /**
     * 修改收费站信息数据
     */
    @PreAuthorize("@ss.hasPermi('system:lane:edit')")
    @Log(title = "收费站信息数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Lane lane) {
        return toAjax(laneService.updateById(lane));
    }

    /**
     * 删除收费站信息数据
     */
    @PreAuthorize("@ss.hasPermi('system:lane:remove')")
    @Log(title = "收费站信息数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(laneService.removeByIds(Arrays.asList(ids)));
    }
}
